<?php
namespace Cyfy\Modules\ListBoxes\Forms;

use \Cyfy\Modules\Forms;
use \Cyfy\Modules\ListBoxes\Module;

/**
  *	Create a new listbox item
  */
class EditItem extends Forms\Form{

	function structure()
	{
        $this -> permission("ListBoxes", "administration");
        $this -> stay = true;
     
        $i = new Forms\TextBox("name", self :: t(10));
        $i -> required = true;
        $this -> addItem($i);
    
		$i = new Forms\File("image", self :: t(20), \Cyfy\Cyfy ::  $filesDir . Module :: DIR . $this -> getTemp("lid") . "/", 0, 0, array("jpg", "png", "gif"));
        $i -> maxFiles = 1;
		$this -> addItem($i);
    
        $w = new Forms\WysiwygEditor("content", self :: t(30));
		$w -> required = true;
		$this -> addItem($w);
		
		$b = new Forms\Button(self :: t(40));
        $this -> addButton($b);
	}
	
	function submit()
	{
        $values = array(
            "name" => $this -> get("name"),
            "content" => $this -> get("content"),
        );
        // if image
        $img = array_pop($this -> get("image"));
        if($img)
        {
            $values['image'] = $img;
        }
        
        
		if(\dibi :: query("UPDATE [:cyfy:ListBoxes-items] SET %a", $values, " WHERE [liid] = %i", $this -> getTemp("liid")))
        {
			\Cyfy\Message::set(self :: t(51, array($this->get("name"))));
		}
		return true;
	}
}
 
